package com.east.sng.controller;

import com.east.sng.service.SyslogService;
import com.github.pagehelper.PageHelper;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * @author east
 * @date: 2021/1/3
 * @Description:
 **/
@Controller
@RequiresRoles("0")
@RequestMapping("/syslog")
public class SyslogController {
    @Autowired
    private SyslogService syslogService;

    /**
     * 日志信息页面跳转
     * @param pageNum
     * @param pageSize
     * @param model
     * @return
     */
    @RequiresPermissions("syslog:list")
    @RequestMapping(value = "/list",method = RequestMethod.GET)
    public String list(@RequestParam(name="pn",defaultValue="1")Integer pageNum,
                       @RequestParam(name = "pSize", defaultValue = "5") Integer pageSize,
                       Model model){
        model.addAttribute("page", PageHelper.startPage(pageNum, pageSize));
        model.addAttribute("syslogs",this.syslogService.findSyslogs());
        return "system/logList";
    }

    /**
     * 日志信息批量删除
     * @param ids
     * @return
     */
    @RequiresPermissions("syslog:list")
    @RequestMapping(value = "/removes",method = RequestMethod.POST)
    @ResponseBody
    public String removeCourses(Integer[] ids){
        return this.syslogService.batchRemoveSyslogs(Arrays.asList(ids))?"success":"fail";
    }

}
